package com.suyang.syt.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.suyang.syt.auth.AuthClass;
import com.suyang.syt.auth.AuthMethod;
import com.suyang.syt.model.User;
import com.suyang.syt.model.dto.AjaxObj;
import com.suyang.syt.util.StringUtil;

@Controller
@RequestMapping("/admin")
@AuthClass("login")
public class AdminIndexController {

	@RequestMapping(value = "/index")
	@AuthMethod
	public String indexAdmin() {
		return "index";
	}

	@RequestMapping(value = "/loginVerified", method = RequestMethod.POST)
	@AuthMethod
	@ResponseBody
	public AjaxObj loginVerified(HttpServletRequest request) {
		try {
			HttpSession session = request.getSession();
			User user = (User) session.getAttribute("loginUser");
			boolean isAdmin = (Boolean) session.getAttribute("isAdmin");
			if (user != null && user.getId() > 0) {
				if (isAdmin) {
					return new AjaxObj(1, "验证成功", "listNavAdmin");
				}
			}
			return new AjaxObj(0, "您没有权限登陆系统");
		} catch (Exception e) {
			return new AjaxObj(0, StringUtil.ERROR_MSG);
		}
	}

}